-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Post processing example improvements #5902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post processing example improvements #5902
Conversation
|
Coming from annieversary#1, where the resizing is working 🎉 Unfortunately, at the current state of this PR, the resizing doesn't work as expected, but I'm unsure why. I'm gonna work through differences betweens these similar looking codes and try to fix it. If anyone has ideas you're most welcome to share 👍 |
9c8a571 to
a885e03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resizing is working 🎉
post_processing_resizing.mp4
addressed issues
I need to research a bit how to limit the updates to the post processing material
This was adressed by bd87a21#diff-d7696ffdd45f974d95c03442261f195c34b196b587b29db22ad1ecd6eae7f4acR149
- also, there is a column artifact on the side of the screen which you can see in following gif.
This is actually a shader specific problem, to have chromatic aberration working on the sides, we should render to a larger rendertarget image and/or have a bigger fullscreen triangle. I don't want to address this issue in this PR, it was already existing previously.
Another solution is to change the shader example to something simpler like a "black and white" or blur effect 🤷.
| .spawn_bundle(Camera2dBundle { | ||
| camera: Camera { | ||
| // renders after the first main camera which has default value: 0. | ||
| priority: camera.priority + 10, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed that from priority: 1 because it makes it easier to make it work with split screen example
| let post_processing_pass_layer = | ||
| RenderLayers::layer((RenderLayers::TOTAL_LAYERS - 1) as u8); | ||
| let half_extents = Vec2::new(size.width as f32 / 2f32, size.height as f32 / 2f32); | ||
| let mut triangle_mesh = Mesh::new(PrimitiveTopology::TriangleList); | ||
| // NOTE: positions are actually not used because the vertex shader maps UV and clip space. | ||
| triangle_mesh.insert_attribute( | ||
| Mesh::ATTRIBUTE_POSITION, | ||
| vec![ | ||
| [-half_extents.x, -half_extents.y, 0.0], | ||
| [half_extents.x * 3f32, -half_extents.y, 0.0], | ||
| [-half_extents.x, half_extents.y * 3f32, 0.0], | ||
| ], | ||
| ); | ||
| triangle_mesh.set_indices(Some(Indices::U32(vec![0, 1, 2]))); | ||
| triangle_mesh.insert_attribute( | ||
| Mesh::ATTRIBUTE_NORMAL, | ||
| vec![[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], | ||
| ); | ||
|
|
||
| triangle_mesh.insert_attribute( | ||
| Mesh::ATTRIBUTE_UV_0, | ||
| vec![[2.0, 0.0], [0.0, 2.0], [0.0, 0.0]], | ||
| ); | ||
| let triangle_handle = meshes.add(triangle_mesh); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've written that positions are not used, but it's probably a lie, as if I change them a bit I notice it's not working properly ; I'm open to suggestions to explain what's happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least on my end (macos/m1), things seem to work properly as long as some positions are set, even
triangle_mesh.insert_attribute(
Mesh::ATTRIBUTE_POSITION,
vec![[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]],
);| commands | ||
| .entity(entity) | ||
| // add the handle to the camera so we can access it and change the percentages | ||
| .insert(material_handle.clone()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so fan of adding a raw handle as component but at least it's simple.
| let material_handle = post_processing_materials.add(PostProcessingMaterial { | ||
| source_image: image_handle.clone(), | ||
| offset_r: Vec2::new(0.1f32, 0.1f32), | ||
| offset_g: Vec2::new(0.1f32, -0.1f32), | ||
| offset_b: Vec2::new(-0.1f32, -0.1f32), | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those will get overwritten quickly in the update_material
IceSentry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of naming nitpicks.
Can you explain why you couldn't use a Quad like the original example? This is example is already pretty complicated and using a custom mesh complicates it even more.
Co-authored-by: Charles <IceSentry@users.noreply.github.com>
It was a feedback from the original post processing PR: #4797 (review) I was mostly curious to see if I could implement it correctly and have feedbacks about it. You surely have a good point though, I can make it into a separate PR, where we could focus on benchmarking it too. |
|
Right, I guess a fullscreen triangle would be better. Personally, it feels a bit out of scope for the example, but it does make sense to push people in that direction until we have first party support. |
Co-authored-by: Charles <IceSentry@users.noreply.github.com>
It might be wiser to exclude it indeed from that PR, as when looking into #5902 ; I think it's a better way of implementing a fullscreen triangle than what I did. But removing the shader vertex makes the resizing to fail (the quad no longer takes the full screen) ; so I'll let it as-is and wait for more feedbacks. |
| option_window_id = Some(*window_id); | ||
| Extent3d { | ||
| width: window.physical_width(), | ||
| height: window.physical_height(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect and doesn't work with UI scaling. The correct solution is either
let scale = window.scale_factor();
// ...
width: (window.physical_width() as f64 / scale) as u32,
height: (window.physical_height() as f64 / scale) as u32,or just the simpler alternative that already returns the logical dimensions
width: window.width() as u32,
height: window.height() as u32,| let window = windows.get(fit_to_window.window_id).expect("PostProcessingCamera is rendering to a window, but this window could not be found"); | ||
| Extent3d { | ||
| width: window.physical_width(), | ||
| height: window.physical_height(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, same as noted here https://github.com/bevyengine/bevy/pull/5902/files#r1014476079
|
It would be nice if a rendering SME could weigh in, but it seems like the vertex shader may be the cleanest way to support resizing properly. If that's the case, I feel like it is worth the extra complexity. I think we could at least tuck the mesh generation code into a separate function. |
|
Actually, this seems to exist now: https://docs.rs/bevy/latest/bevy/core_pipeline/fullscreen_vertex_shader/index.html Is that stuff useful here? |
|
I'm closing this because the example was completely reworked with #8376 |
Fix #5315
Also: